//
//  SSDKPluginJsonUtil.m
//  SSDKPlugin-demo
//
//  Created by 涂俊 on 2017/7/5.
//  Copyright © 2017年 涂俊. All rights reserved.
//

#import "SSDKPluginJsonUtil.h"

@implementation SSDKPluginJsonUtil

+ (NSString *)toJsonWithObject:(id)obj {
    NSError *writeError = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:obj
                                                       options:0
                                                         error:&writeError];
    
    if (jsonData) {
        NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        return jsonStr;
    }
    NSLog(@"%@", writeError);
    return @"";
}

+ (id)toObjectWithJson:(NSString *)json {
    NSError *readError = nil;
    
    NSData *data = [json dataUsingEncoding:NSUTF8StringEncoding];
    id obj = [NSJSONSerialization JSONObjectWithData:data options:0 error:&readError];
    if (!obj) {
        NSLog(@"%@", readError);
    }
    return obj;
}

@end
